package com.qidian.by.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qidian.by.goods.dto.ItemSpeInfoDTO;
import com.qidian.by.goods.mapper.ItemSpecificationItemMapper;
import com.qidian.by.goods.mapper.ItemSpecificationMapper;
import com.qidian.by.goods.service.IItemSpecificationItemService;
import com.qidian.by.goods.service.IItemSpecificationService;
import com.qidian.by.pojo.goods.entity.ItemSpecification;
import com.qidian.by.pojo.goods.entity.ItemSpecificationItem;
import com.qidian.by.util.pojo.EsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小可怎么都睡不够
 * @since 2024-05-08
 */
@Service
public class ItemSpecificationItemServiceImpl implements IItemSpecificationItemService {
    @Autowired
    private ItemSpecificationItemMapper itemSpeMapper;

    @Autowired
    private ItemSpecificationMapper speMapper;
    @Override
    public EsResult<List<ItemSpecificationItem>> list(Long speId) {
        QueryWrapper<ItemSpecificationItem> wrapper = new QueryWrapper<>();
        wrapper.eq("spe_id",speId);
        return EsResult.ok("查询成功",itemSpeMapper.selectList(wrapper));
    }

    @Override
    public EsResult save(ItemSpecificationItem itemSpecificationItem) {
        return EsResult.isSuccess(itemSpeMapper.insert(itemSpecificationItem));
    }

    @Override
    public EsResult queryByItemIdByNotAt(Long itemId) {
        //查询已有列表
        List<ItemSpecification> at = speMapper.selectByItemId(itemId);
        //查询不存在的列表
        List<ItemSpecification> notAt = speMapper.selectAll(itemId);
        ItemSpeInfoDTO res = new ItemSpeInfoDTO();
        res.setAt(at);
        res.setNotAt(notAt);
        return EsResult.ok(res);
    }
}
